import { defineStore } from "pinia";
import { ref } from "vue";

function initState() {
  return {
    isCollapse: false,
    tags: [
      {
        path: "/home",
        name: "home",
        label: "首页",
      },
    ],
    currentTag: null,
    loginUserInfo: null
  };
}
export const useAllStoreData = defineStore("allData", () => {
  // 初始化
  const state = ref(initState());

  function selectTag(item) {
    if (item.name === "home") {
      state.value.currentTag = null;
    } else {
      state.value.currentTag = item;
      let index = state.value.tags.findIndex((v) => v.path === item.path);
      if (index === -1) {
        state.value.tags.push(item);
      }
    }
  }

  function updateTag(tag) {
    const index = state.value.tags.findIndex((f) => f.path === tag.path);
    state.value.tags.splice(index, 1);
  }


  return {
    state,
    selectTag,
    updateTag,
  };
});
